{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "Optimizing the number of centroids"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.datasets import make_blobs\n",
    "import numpy as np\n",
    "blobs, classes = make_blobs(500, centers=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300,\n",
       "    n_clusters=3, n_init=10, n_jobs=1, precompute_distances='auto',\n",
       "    random_state=None, tol=0.0001, verbose=0)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.cluster import KMeans\n",
    "kmean = KMeans(n_clusters=3)\n",
    "kmean.fit(blobs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.        ,  0.13648469],\n",
       "       [ 1.        ,  0.64771514],\n",
       "       [ 0.        ,  0.5335237 ],\n",
       "       [ 1.        ,  0.66078185],\n",
       "       [ 0.        ,  0.66130148]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn import metrics\n",
    "silhouette_samples = metrics.silhouette_samples(blobs, kmean.labels_)\n",
    "np.column_stack((classes[:5], silhouette_samples[:5]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.61380435271966061"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "silhouette_samples.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.61380435271966061"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "metrics.silhouette_score(blobs, kmean.labels_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0xac5ee10>]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAbUAAAE4CAYAAADchG3bAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmYFNX59vHvw+KGikFEEUQQUOKGKwHXQVBR44qiaIzG\nqGjcNT9xiZEYNTHuezQurxoTYzQo4orRMZpgBFcUCIiA7AKCgAgMM8/7x+mRZuiZrl5mqpf7c11z\nMV1dVf1MMdN3n1OnTpm7IyIiUgqaxV2AiIhIvijURESkZCjURESkZCjURESkZCjURESkZCjURESk\nZEQKNTMbYGYTzWySmQ2tZ50KM/vQzD41szeTlk8zs48Tz72Xr8JFRETqsnTXqZlZM2AS0A+YDYwB\nTnL3iUnrtAb+Axzi7rPMrK27L0g89wWwp7svaqSfQUREBIjWUusFTHb36e5eBTwFHF1nnZOBZ919\nFkBtoCVYxNcRERHJSZSw6QDMSHo8M7Es2fZAGzN708zGmNmpSc85MCqx/KzcyhUREalfizzuZw/g\nIKAVMNrMRrv758C+7j7HzLYghNsEd38nT68rIiLyvSihNgvolPS4Y2JZspnAAndfAawws38BPYHP\n3X0OgLvPN7PhhO7MdULNzDQJpYiIrMXdLZP1o3Q/jgG6mdm2ZrYecBIwos46zwP7mVlzM9sI+BEw\nwcw2MrONAcysFXAI8GkDxZf117XXXht7DXF/6RjoGOgY6BjUfmUjbUvN3avN7HzgNUIIPuzuE8xs\nSHjaH3T3iWb2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h+uJ76uAt4DnqYMjoOZ7QI8Rvjd\nbwb8zd1vMLM2lMkxSGZmBwKXuftR5XYMzKwLMJzwd9ACeNLdf1+Gx6En4dZlLYEvgJ8BzcngGMQe\naiIiIvkSd/ejiIhI3ijURESkZCjURESkZCjURESkZCjURESkZCjURESkZCjURESkZCjURESkZPx/\ntN8FCxUNvYQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xa9fb7f0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "blobs, classes = make_blobs(500, centers=10)\n",
    "silhouette_avgs = []\n",
    "for k in range(2, 60):\n",
    "     kmean = KMeans(n_clusters=k).fit(blobs)\n",
    "     silhouette_avgs.append(metrics.silhouette_score(blobs, kmean.labels_))\n",
    "\n",
    "f, ax = plt.subplots(figsize=(7, 5))\n",
    "ax.plot(silhouette_avgs)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
